<template>
  <el-dialog :visible.sync="visible" v-dialogDrag :title="title" :close-on-click-modal="false" :modal-append-to-body="true" :append-to-body="true" class="tl-dialog" width="1200px" @open="open" @close="close">
    <el-form class="tl-form" ref="form" :model="model" :rules="rules" label-width="150px" :disabled="disableEditSubmit">
      <el-row>
        <el-col :span="24">
          <el-form-item label="包号" prop="bidpackagenumber" :rules="rules.validateRequire">
            <el-input v-model="model.bidpackagenumber"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="中标结果" prop="bidresult" :rules="rules.validateRequire">
            <el-select v-model="model.bidresult" filterable clearable @change="changebidresult">
              <el-option v-for="item in codeModel.bidresultList" :key="item.code" :label="item.name" :value="item.code" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="中标结果公告时间" prop="bulletintime" :rules="iswininfodisable ? [] : rules.validateRequire">
            <el-date-picker v-model="model.bulletintime" type="date" placeholder="中标结果公告时间" value-format="yyyy-MM-dd" :disabled="iswininfodisable"></el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="是否可参与" prop="partake" :rules="iswininfodisable ? [] : rules.validateRequire">
            <el-select v-model="model.partake" filterable clearable :disabled="iswininfodisable">
              <el-option v-for="item in codeModel.enabledList" :key="item.code" :label="item.name" :value="item.code" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="中标厂家" prop="bidmanufactor" :rules="iswininfodisable ? [] : rules.validateRequire">
            <el-input v-model="model.bidmanufactor" :disabled="iswininfodisable"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="中标金额" prop="bidwinfund" :rules="iswininfodisable ? [] : rules.validateRequire">
            <el-input v-model="model.bidwinfund" min="0" type="number" :disabled="iswininfodisable">
              <label slot="append">
                万元
              </label>
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button :type="disableEditSubmit === false ? 'text' : 'primary'" @click="doCancelEdit">取消</el-button>
      <el-button type="primary" @click="doSubmitEdit" :loading="saveLoading" v-if="disableEditSubmit === false">确认</el-button>
    </div>
  </el-dialog>
</template>

<script>
/** mixins */
import { mixin_edit } from '@tapui/mixins/mixin_edit'
/** 子组件 */
/** 工具类 */
import { putAction, getAction, postAction, deleteAction } from '@tapui/utils/http'
/** VUE配置 */
export default {
  mixins: [mixin_edit],
  components: {},
  data() {
    return {
      moduleTitle: '中标信息',
      urlPrefix: '/mpm/projectWinBidInfo/',
      url: {
        // 额外的url
      }
    }
  },
  props: {
    reviewModel: {
      default: function() {
        return {}
      },
      type: Object
    }
  },
  computed: {
    iswininfodisable() {
      return this.model.bidresult && this.model.bidresult === '3'
    }
  },
  methods: {
    open() {
      this.model = {}
      this.$nextTick(() => {
        this.$refs.form.clearValidate()
        if (this.isAdd === true) {
          this.title = '添加' + this.moduleTitle
          // 需要添加重复判断
          if (this.$store.getters.param.isAvoidRepeat === true) {
            this.queryBillUid()
          }
          if (this.isQueryInitData === true) {
            // 后台进行数据初始化
            this.queryInitData().then((_) => {
              this.assignDefaultValue()
              this.$refs.form.clearValidate()
              this.loaded()
            })
          } else {
            // 前台进行数据初始化
            this.$set(this.model, 'enabled', 1)
            this.$set(this.model, 'sortcode', 0)
            this.assignDefaultValue()
            this.$refs.form.clearValidate()
            this.loaded()
          }
          // 新增时赋初始值
          this.$set(this.model, 'projectname', this.reviewModel.projectname)
          this.$set(this.model, 'projectcode', this.reviewModel.projectcode)
          this.$set(this.model, 'reviewid', this.reviewModel.id)
        } else if (this.disableEditSubmit === false) {
          this.title = '编辑' + this.moduleTitle
          this.queryData(this.id).then((_) => {
            this.loaded()
          })
        } else {
          this.title = '查看' + this.moduleTitle
          this.queryData(this.id).then((_) => {
            this.$refs.form.clearValidate()
            this.loaded()
          })
        }
      })
    },
    changebidresult() {
      if (this.model.bidresult && this.model.bidresult === '3') {
        this.model.bidwinfund = ''
        this.model.bidmanufactor = ''
        this.model.partake = ''
        this.model.bulletintime = null
      }
    }
  }
}
</script>
